/* 
	Derived from a script by Dziudek. 
	Author: GavickPro <support@gavick.com>     
	version: 2.6
*/

window.addEvent("load", function(){
	var GA = 5;
	var GMA = [3,3,3,3,3,3];
	
	var margin_tab = [
		false,
		[0,0],[10,0],[0,0],
		[0,0],[10,0],[0,0],
		[0,0],[10,0],[0,0],
		[0,0],[10,0],[0,0],
		[0,0],[10,0],[0,0],
		[0,0],[10,0],[0,0]
	];
	
	var base = 1;
	var k = 1; 
	var sum = [false];
	
	margin_tab.each(function(el,i){
		sum[i] = (!!el) ? (el[0] + el[1]) : false;
	});
	
	for(var j=0;j<GA;j++){
		if($("user_position-"+(j+1))){ 
			var parent_width = ($("user_position-"+(j+1)).getSize().size.x) - 1; 
			var border = 0;
			var gk_array = [false];
			var a = 0;
			var sum_t = 0;			
			
			if($E("div.us_"+(j+1)+"-left")){
				gk_array[base+1] = $E("div.us_"+(j+1)+"-left");
				sum_t = sum_t + sum[base+1];		
				a++;
			}else{
				gk_array[base+1] = false;
			}
			
			if($E("div.us_"+(j+1)+"-center")){
				
				for(var k = 2;k < GMA[j];k++){
					
					if($ES("div.us_"+(j+1)+"-center")[k-2]){
						if($E("div.us_"+(j+1)+"-center") && !$E("div.us_"+(j+1)+"-left")){
							gk_array[base+k-2] = $E("div.us_"+(j+1)+"-center");	
							gk_array[base+k] = false;	
							sum_t = sum_t + sum[base+k-2];	
							a++;
						}else{
							gk_array[base+k] = $ES("div.us_"+(j+1)+"-center")[k-2];
							sum_t = sum_t + sum[base+k];
							a++;
						}
					}else{
						gk_array[base+k] = false;
					}
				}
			}
			
			if($E("div.us_"+(j+1)+"-right")){	
				gk_array[base+GMA[j]] = $E("div.us_"+(j+1)+"-right");
				sum_t = sum_t + sum[base+GMA[j]];		
				a++;
			}else{
				gk_array[base+GMA[j]] = false;
			}
			
			var width = Math.floor((parent_width - sum_t) / a);
			var ix = 0;
			var str = '';
			
			if(window.ie){
				var gk_array_n = [];
				var i = 0;
				gk_array.forEach(function(el){
					if($defined(el)){
						gk_array_n[i] = el;
						i++;
					}
				});	
				gk_array = gk_array_n;
			}
			
			gk_array.forEach(function(el){
				if(el != false){
					el.setStyles({"width":(width-(2*border)) + "px"});
					el.setStyles({
						"margin-right" : margin_tab[base+ix-1][1] + "px",
						"margin-left" : margin_tab[base+ix-1][0] + "px"
					});
				}
				ix++;
			});	
			base = base + GMA[j];
		}
	}
	
	$$("#jwscroller-inner img").setStyle("border","none");
});